AbstractValidator<T>
Base class for object validators.
Assembly: ServiceStack.dll
View Source
public abstract class AbstractValidator<T> : IValidator<T>, IValidator, IEnumerable<IValidationRule>, IEnumerable, IRequiresRequest, IHasTypeValidators, IServiceStackValidator
Properties
CascadeMode
Sets the cascade mode for all rules within this validator.
View Source
public CascadeMode CascadeMode { get; set; }
TypeValidators
View Source
public List<ITypeValidator> TypeValidators { get; }
Request
View Source
public virtual IRequest Request { get; set; }
Gateway
View Source
public virtual IServiceGateway Gateway { get; }
Methods
IValidator.Validate(IValidationContext)
View Source
ValidationResult IValidator.Validate(IValidationContext context)
Returns
ServiceStack.FluentValidation.Results.ValidationResult
Parameters
Type | Name |
---|---|
ServiceStack.FluentValidation.IValidationContext | context |
IValidator.ValidateAsync(IValidationContext, CancellationToken)
View Source
Task<ValidationResult> IValidator.ValidateAsync(IValidationContext context, CancellationToken cancellation)
Returns
System.Threading.Tasks.Task<ServiceStack.FluentValidation.Results.ValidationResult>
Parameters
Type | Name |
---|---|
ServiceStack.FluentValidation.IValidationContext | context |
System.Threading.CancellationToken | cancellation |
Validate(T)
Validates the specified instance
View Source
public ValidationResult Validate(T instance)
Returns
ServiceStack.FluentValidation.Results.ValidationResult: A ValidationResult object containing any validation failures
Parameters
Type | Name | Description |
---|---|---|
<T> | instance | The object to validate |
|
ValidateAsync(T, CancellationToken)
Validates the specified instance asynchronously
View Source
public Task<ValidationResult> ValidateAsync(T instance, CancellationToken cancellation = default(CancellationToken))
Returns
System.Threading.Tasks.Task<ServiceStack.FluentValidation.Results.ValidationResult>
: A ValidationResult object containing any validation failures
Parameters
Type | Name | Description |
---|---|---|
<T> | instance | The object to validate |
|
| System.Threading.CancellationToken
| cancellation | Cancellation token
|
Validate(ValidationContext<T>)
Validates the specified instance.
View Source
public virtual ValidationResult Validate(ValidationContext<T> context)
Returns
ServiceStack.FluentValidation.Results.ValidationResult: A ValidationResult object containing any validation failures.
Parameters
Type | Name | Description |
---|---|---|
ServiceStack.FluentValidation.ValidationContext<T> | context | Validation Context |
|
ValidateAsync(ValidationContext<T>, CancellationToken)
Validates the specified instance asynchronously.
View Source
public virtual async Task<ValidationResult> ValidateAsync(ValidationContext<T> context, CancellationToken cancellation = default(CancellationToken))
Returns
System.Threading.Tasks.Task<ServiceStack.FluentValidation.Results.ValidationResult>
: A ValidationResult object containing any validation failures.
Parameters
Type | Name | Description |
---|---|---|
ServiceStack.FluentValidation.ValidationContext<T> | context | Validation Context |
|
| System.Threading.CancellationToken
| cancellation | Cancellation token
|
AddRule(IValidationRule)
Adds a rule to the current validator.
View Source
protected void AddRule(IValidationRule rule)
Parameters
Type | Name |
---|---|
ServiceStack.FluentValidation.IValidationRule | rule |
CreateDescriptor()
Creates a ServiceStack.FluentValidation.IValidatorDescriptor that can be used to obtain metadata about the current validator.
View Source
public virtual IValidatorDescriptor CreateDescriptor()
Returns
ServiceStack.FluentValidation.IValidatorDescriptor
IValidator.CanValidateInstancesOfType(Type)
View Source
bool IValidator.CanValidateInstancesOfType(Type type)
Returns
System.Boolean
Parameters
Type | Name |
---|---|
System.Type | type |
RuleFor<TProperty>(Expression<Func<T, TProperty>>)
Defines a validation rule for a specify property.
View Source
public IRuleBuilderInitial<T, TProperty> RuleFor<TProperty>(Expression<Func<T, TProperty>> expression)
Returns
ServiceStack.FluentValidation.IRuleBuilderInitial<<T>,<TProperty>>
: an IRuleBuilder instance on which validators can be defined
Parameters
Type | Name | Description |
---|---|---|
System.Linq.Expressions.Expression<System.Func<<T>,<TProperty>>> | expression | The expression representing the property to validate |
|
Type Parameters
Name | Description |
---|---|
TProperty | The type of property being validated |
Transform<TProperty, TTransformed>(Expression<Func<T, TProperty>>, Func<TProperty, TTransformed>)
Defines a validation rule for a specify property and transform it to a different type.
View Source
public IRuleBuilderInitial<T, TTransformed> Transform<TProperty, TTransformed>(Expression<Func<T, TProperty>> from, Func<TProperty, TTransformed> to)
Returns
ServiceStack.FluentValidation.IRuleBuilderInitial<<T>,<TTransformed>>
: an IRuleBuilder instance on which validators can be defined
Parameters
Type | Name | Description |
---|---|---|
System.Linq.Expressions.Expression<System.Func<<T>,<TProperty>>> | from | The expression representing the property to transform |
|
| System.Func<<TProperty>,<TTransformed>>
| to | Function to transform the property value into a different type
|
Type Parameters
Name | Description |
---|---|
TProperty | The type of property being validated |
TTransformed | The type after the transformer has been applied |
Transform<TProperty, TTransformed>(Expression<Func<T, TProperty>>, Func<T, TProperty, TTransformed>)
Defines a validation rule for a specify property and transform it to a different type.
View Source
public IRuleBuilderInitial<T, TTransformed> Transform<TProperty, TTransformed>(Expression<Func<T, TProperty>> from, Func<T, TProperty, TTransformed> to)
Returns
ServiceStack.FluentValidation.IRuleBuilderInitial<<T>,<TTransformed>>
: an IRuleBuilder instance on which validators can be defined
Parameters
Type | Name | Description |
---|---|---|
System.Linq.Expressions.Expression<System.Func<<T>,<TProperty>>> | from | The expression representing the property to transform |
|
| System.Func<<T>,<TProperty>,<TTransformed>>
| to | Function to transform the property value into a different type
|
Type Parameters
Name | Description |
---|---|
TProperty | The type of property being validated |
TTransformed | The type after the transformer has been applied |
RuleForEach<TElement>(Expression<Func<T, IEnumerable<TElement>>>)
Invokes a rule for each item in the collection.
View Source
public IRuleBuilderInitialCollection<T, TElement> RuleForEach<TElement>(Expression<Func<T, IEnumerable<TElement>>> expression)
Returns
ServiceStack.FluentValidation.IRuleBuilderInitialCollection<<T>,<TElement>>
: An IRuleBuilder instance on which validators can be defined
Parameters
Type | Name | Description |
---|---|---|
System.Linq.Expressions.Expression<System.Func<<T>,System.Collections.Generic.IEnumerable<<TElement>>>> | expression | Expression representing the collection to validate |
|
Type Parameters
Name | Description |
---|---|
TElement | Type of property |
TransformForEach<TElement, TTransformed>(Expression<Func<T, IEnumerable<TElement>>>, Func<TElement, TTransformed>)
Invokes a rule for each item in the collection, transforming the element from one type to another.
View Source
public IRuleBuilderInitialCollection<T, TTransformed> TransformForEach<TElement, TTransformed>(Expression<Func<T, IEnumerable<TElement>>> expression, Func<TElement, TTransformed> to)
Returns
ServiceStack.FluentValidation.IRuleBuilderInitialCollection<<T>,<TTransformed>>
: An IRuleBuilder instance on which validators can be defined
Parameters
Type | Name | Description |
---|---|---|
System.Linq.Expressions.Expression<System.Func<<T>,System.Collections.Generic.IEnumerable<<TElement>>>> | expression | Expression representing the collection to validate |
|
| System.Func<<TElement>,<TTransformed>>
| to | Function to transform the collection element into a different type
|
Type Parameters
Name | Description |
---|---|
TElement | Type of property |
TTransformed | The type after the transformer has been applied |
TransformForEach<TElement, TTransformed>(Expression<Func<T, IEnumerable<TElement>>>, Func<T, TElement, TTransformed>)
Invokes a rule for each item in the collection, transforming the element from one type to another.
View Source
public IRuleBuilderInitialCollection<T, TTransformed> TransformForEach<TElement, TTransformed>(Expression<Func<T, IEnumerable<TElement>>> expression, Func<T, TElement, TTransformed> to)
Returns
ServiceStack.FluentValidation.IRuleBuilderInitialCollection<<T>,<TTransformed>>
: An IRuleBuilder instance on which validators can be defined
Parameters
Type | Name | Description |
---|---|---|
System.Linq.Expressions.Expression<System.Func<<T>,System.Collections.Generic.IEnumerable<<TElement>>>> | expression | Expression representing the collection to validate |
|
| System.Func<<T>,<TElement>,<TTransformed>>
| to | Function to transform the collection element into a different type
|
Type Parameters
Name | Description |
---|---|
TElement | Type of property |
TTransformed | The type after the transformer has been applied |
RuleSet(String, Action)
Defines a RuleSet that can be used to group together several validators.
View Source
public void RuleSet(string ruleSetName, Action action)
Parameters
Type | Name | Description |
---|---|---|
System.String | ruleSetName | The name of the ruleset. |
|
| System.Action
| action | Action that encapsulates the rules in the ruleset.
|
When(Func<T, Boolean>, Action)
Defines a condition that applies to several rules
View Source
public IConditionBuilder When(Func<T, bool> predicate, Action action)
Returns
ServiceStack.FluentValidation.IConditionBuilder
Parameters
Type | Name | Description |
---|---|---|
System.Func<<T>,System.Boolean> | predicate | The condition that should apply to multiple rules |
|
| System.Action
| action | Action that encapsulates the rules.
|
When(Func<T, ValidationContext<T>, Boolean>, Action)
Defines a condition that applies to several rules
View Source
public IConditionBuilder When(Func<T, ValidationContext<T>, bool> predicate, Action action)
Returns
ServiceStack.FluentValidation.IConditionBuilder
Parameters
Type | Name | Description |
---|---|---|
System.Func<<T>,ServiceStack.FluentValidation.ValidationContext<<T>>,System.Boolean> | predicate | The condition that should apply to multiple rules |
|
| System.Action
| action | Action that encapsulates the rules.
|
Unless(Func<T, Boolean>, Action)
Defines an inverse condition that applies to several rules
View Source
public IConditionBuilder Unless(Func<T, bool> predicate, Action action)
Returns
ServiceStack.FluentValidation.IConditionBuilder
Parameters
Type | Name | Description |
---|---|---|
System.Func<<T>,System.Boolean> | predicate | The condition that should be applied to multiple rules |
|
| System.Action
| action | Action that encapsulates the rules
|
Unless(Func<T, ValidationContext<T>, Boolean>, Action)
Defines an inverse condition that applies to several rules
View Source
public IConditionBuilder Unless(Func<T, ValidationContext<T>, bool> predicate, Action action)
Returns
ServiceStack.FluentValidation.IConditionBuilder
Parameters
Type | Name | Description |
---|---|---|
System.Func<<T>,ServiceStack.FluentValidation.ValidationContext<<T>>,System.Boolean> | predicate | The condition that should be applied to multiple rules |
|
| System.Action
| action | Action that encapsulates the rules
|
WhenAsync(Func<T, CancellationToken, Task<Boolean>>, Action)
Defines an asynchronous condition that applies to several rules
View Source
public IConditionBuilder WhenAsync(Func<T, CancellationToken, Task<bool>> predicate, Action action)
Returns
ServiceStack.FluentValidation.IConditionBuilder
Parameters
Type | Name | Description |
---|---|---|
System.Func<<T>,System.Threading.CancellationToken,System.Threading.Tasks.Task<System.Boolean>> | predicate | The asynchronous condition that should apply to multiple rules |
|
| System.Action
| action | Action that encapsulates the rules.
|
WhenAsync(Func<T, ValidationContext<T>, CancellationToken, Task<Boolean>>, Action)
Defines an asynchronous condition that applies to several rules
View Source
public IConditionBuilder WhenAsync(Func<T, ValidationContext<T>, CancellationToken, Task<bool>> predicate, Action action)
Returns
ServiceStack.FluentValidation.IConditionBuilder
Parameters
Type | Name | Description |
---|---|---|
System.Func<<T>,ServiceStack.FluentValidation.ValidationContext<<T>>,System.Threading.CancellationToken,System.Threading.Tasks.Task<System.Boolean>> | predicate | The asynchronous condition that should apply to multiple rules |
|
| System.Action
| action | Action that encapsulates the rules.
|
UnlessAsync(Func<T, CancellationToken, Task<Boolean>>, Action)
Defines an inverse asynchronous condition that applies to several rules
View Source
public IConditionBuilder UnlessAsync(Func<T, CancellationToken, Task<bool>> predicate, Action action)
Returns
ServiceStack.FluentValidation.IConditionBuilder
Parameters
Type | Name | Description |
---|---|---|
System.Func<<T>,System.Threading.CancellationToken,System.Threading.Tasks.Task<System.Boolean>> | predicate | The asynchronous condition that should be applied to multiple rules |
|
| System.Action
| action | Action that encapsulates the rules
|
UnlessAsync(Func<T, ValidationContext<T>, CancellationToken, Task<Boolean>>, Action)
Defines an inverse asynchronous condition that applies to several rules
View Source
public IConditionBuilder UnlessAsync(Func<T, ValidationContext<T>, CancellationToken, Task<bool>> predicate, Action action)
Returns
ServiceStack.FluentValidation.IConditionBuilder
Parameters
Type | Name | Description |
---|---|---|
System.Func<<T>,ServiceStack.FluentValidation.ValidationContext<<T>>,System.Threading.CancellationToken,System.Threading.Tasks.Task<System.Boolean>> | predicate | The asynchronous condition that should be applied to multiple rules |
|
| System.Action
| action | Action that encapsulates the rules
|
Include(IValidator<T>)
Includes the rules from the specified validator
View Source
public void Include(IValidator<T> rulesToInclude)
Parameters
Type | Name |
---|---|
ServiceStack.FluentValidation.IValidator<T> | rulesToInclude |
Include<TValidator>(Func<T, TValidator>)
Includes the rules from the specified validator
View Source
public void Include<TValidator>(Func<T, TValidator> rulesToInclude)
where TValidator : IValidator<T>
Parameters
Type | Name |
---|---|
System.Func<<T>,<TValidator>> | rulesToInclude |
Type Parameters
TValidator
GetEnumerator()
Returns an enumerator that iterates through the collection of validation rules.
View Source
public IEnumerator<IValidationRule> GetEnumerator()
Returns
System.Collections.Generic.IEnumerator<ServiceStack.FluentValidation.IValidationRule>
:
A System.Collections.Generic.IEnumerator%601
that can be used to iterate through the collection.
IEnumerable.GetEnumerator()
View Source
IEnumerator IEnumerable.GetEnumerator()
Returns
System.Collections.IEnumerator
EnsureInstanceNotNull(Object)
Throws an exception if the instance being validated is null.
View Source
protected virtual void EnsureInstanceNotNull(object instanceToValidate)
Parameters
Type | Name |
---|---|
System.Object | instanceToValidate |
PreValidate(ValidationContext<T>, ValidationResult)
Determines if validation should occur and provides a means to modify the context and ValidationResult prior to execution. If this method returns false, then the ValidationResult is immediately returned from Validate/ValidateAsync.
View Source
protected virtual bool PreValidate(ValidationContext<T> context, ValidationResult result)
Returns
System.Boolean
Parameters
Type | Name |
---|---|
ServiceStack.FluentValidation.ValidationContext<T> | context |
ServiceStack.FluentValidation.Results.ValidationResult | result |
RaiseValidationException(ValidationContext<T>, ValidationResult)
Throws a ValidationException. This method will only be called if the validator has been configured to throw exceptions if validation fails. The default behaviour is not to throw an exception.
View Source
protected virtual void RaiseValidationException(ValidationContext<T> context, ValidationResult result)
Parameters
Type | Name |
---|---|
ServiceStack.FluentValidation.ValidationContext<T> | context |
ServiceStack.FluentValidation.Results.ValidationResult | result |
RuleSet(ApplyTo, Action)
Defines a RuleSet that can be used to provide specific validation rules for specific HTTP methods (GET, POST...)
View Source
public void RuleSet(ApplyTo appliesTo, Action action)
Parameters
Type | Name | Description |
---|---|---|
ServiceStack.ApplyTo | appliesTo | The HTTP methods where this rule set should be used. |
|
| System.Action
| action | Action that encapsulates the rules in the ruleset.
|
RemovePropertyRules(Func<PropertyRule, Boolean>)
View Source
public void RemovePropertyRules(Func<PropertyRule, bool> where)
Parameters
Type | Name |
---|---|
System.Func<ServiceStack.FluentValidation.Internal.PropertyRule,System.Boolean> | where |
Implements
- ServiceStack.FluentValidation.IValidator<T>
- ServiceStack.FluentValidation.IValidator
System.Collections.Generic.IEnumerable<ServiceStack.FluentValidation.IValidationRule>
System.Collections.IEnumerable
- ServiceStack.Web.IRequiresRequest
- ServiceStack.IHasTypeValidators
- ServiceStack.FluentValidation.IServiceStackValidator